using System.Collections.Generic;
using System.Xml;

public partial class GameCollection
{
    public class GameVO
    {
        public string Name { get; private set; }

        private readonly List<FolderVO> folderList = new();
        private readonly List<FileVO> fileList = new();

        public IReadOnlyList<FolderVO> Folders => folderList;
        public IReadOnlyList<FileVO> Files => fileList;

        public GameVO(string name)
        {
            Name = name;
        }

        public void Parse(XmlNode gameNode)
        {
            ParseFolder(gameNode);
            ParseFile(gameNode);
        }

        private void ParseFolder(XmlNode gameNode)
        {
            folderList.Clear();

            var folderNode = gameNode.SelectSingleNode("Folders");
            if (folderNode == null) return;

            var childNodes = folderNode.ChildNodes;
            foreach (XmlNode node in childNodes)
            {
                var path = node.Attributes?["Path"].Value;
                if (string.IsNullOrEmpty(path)) continue;
                folderList.Add(new FolderVO(path, this));
            }
        }

        private void ParseFile(XmlNode gameNode)
        {
            fileList.Clear();

            var fileNode = gameNode.SelectSingleNode("Files");
            if (fileNode == null) return;

            var childNodes = fileNode.ChildNodes;
            foreach (XmlNode node in childNodes)
            {
                var path = node.Attributes?["Path"].Value;
                if (string.IsNullOrEmpty(path)) continue;
                fileList.Add(new FileVO(path, this));
            }
        }
    }
}